<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<html>
	<head>
		<title>组织结构管理</title>
		<jsp:include page="../../../common/head.jsp">
			 <jsp:param name="_useTree" value="true"/>
		</jsp:include>
		<SCRIPT>
	var obj=null;
	function  clickEvent(nodeObj)
	{
		obj = nodeObj;
		var str=obj.getAttribute("id");
		var tmp=str.split("#");
		var orgId=tmp[0];
		var orgName = tmp[1];
		window.parent.frame_right.location.href="showOrganization.do?state=A&orgId="+orgId;
	}


	function insOrg()
	{  		
		if(obj!=null)
		{
			var str=obj.id;

			var tmp=str.split("#");
			var orgId = tmp[0];
			var orgName = tmp[1];
			
			if(orgId.indexOf("999")!=-1)
			{
				alert("不能向初始部门下添加下级部门");
				return;
			}
			if(obj.getAttribute("name")=="title")
			{
				orgName="${orgOrganization.orgName}";
				orgId=0;
			}
			window.parent.frame_right.location.href="addOrganization.do?orgPid="+orgId+"&orgName="+orgName;
		}
		else
		{
		    alert("请选择要增加数据的父节点！");
		}
	}
	function updateOrg(orgId)
	{
		if(obj!=null)
		{
			var str=obj.getAttribute("id");
			var tmp=str.split("#");
			var orgId=tmp[0];
			if(obj.getAttribute("name")=="title")
			{
				return;
			}
			else
			{
				window.parent.frame_right.location.href="updateOrganization.do?orgId="+orgId;
			}
		}
		else
		{
		    alert("请选择要修改的组织机构数据！");
		}
	}
	
	function delOrg(){
		if(obj!=null)
		{
			var str=obj.getAttribute("id");
			var tmp=str.split("#");
			var orgId=tmp[0];
			if(obj.getAttribute("name")=="title")
			{
				return;
			}
			else
			{
				if(obj.getAttribute("nextlevel")=="true")
					alert("所选节点含有下组织结构数据，不能删除！");
				else
				{
					if(confirm("确认删除？"))
					{
						var a=ModalWindow("jump.do?path=delOrganization.do&orgId="+orgId,640,480);
						if(a=="ok"){
							window.parent.frame_right.location.href="${ctx}/blank_common.jsp?title=组织结构管理";
							window.location.reload();
						}	
					}
				}
			}
		}
		else
		{
		    alert("请选择要删除的组织机构数据！");
		}
	}
</script>
	</head>
	<body>
		<div id="body_div">
	<w:ShowTitle name="组织结构">
	<w:TitleButton funcName="添加" onClickFunction="insOrg()" urlImg="${ctx}/images/main/add.png"/>
	<w:TitleButton funcName="修改" onClickFunction="updateOrg()" urlImg="${ctx}/images/main/update.png"/>
	</w:ShowTitle>
	<div id="body_content">
<TABLE cellSpacing="1" cellPadding="0" width="100%" border="0">
           <TR>
             <TD>
      <w:tree returnValue="orgId#orgName" regex="#"
      displayValue="orgName" pidname="orgPid" 
      content="${datalist}" idname="orgId" headValue="0" 
      headDisplayValue="${orgOrganization.orgName}"></w:tree>
			</TD>
	</TR>
       </TABLE>
       </div>
	</div>	
	</body>
</html>
